package com.ccoffers.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.ccoffers.dao.CRUDOperations;

public class CRUDOperationsImpl<T> implements CRUDOperations<T> {

	private HibernateTemplate hibernateTemplate;

	public void update(T toUpdate) {
		hibernateTemplate.saveOrUpdate(toUpdate);
	}

	public T retrieve(Class<T> clazz, Serializable id) {
		return hibernateTemplate.get(clazz, id);
	}

	public void create(T toCreate) {
		hibernateTemplate.save(toCreate);
	}

	public void delete(T toDelete) {
		hibernateTemplate.delete(toDelete);

	}

	@Required
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public List<T> loadAll(Class<T> clazz) {
		return hibernateTemplate.loadAll(clazz);
	}

}
